<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link media="all" rel="stylesheet" th:href="@{/libs/layui-v2.5.5/css/layui.css}">
    <link media="all" rel="stylesheet" th:href="@{/css/public.css}">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">旧的密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="旧的密码不能为空" lay-verify="required" name="oldPassword"
                   placeholder="请输入旧的密码" type="password" value="">
            <tip>填写自己账号的旧的密码。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">新的密码</label>
        <div class="layui-input-block">
            <input class="layui-input" lay-reqtext="新的密码不能为空" lay-verify="required" name="newPassword"
                   placeholder="请输入新的密码" type="password" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-filter="saveBtn" lay-submit>确认保存</button>
        </div>
    </div>
</div>
<script charset="utf-8" th:src="@{/libs/layui-v2.5.5/layui.js}"></script>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            laydate = layui.laydate;

        laydate.render({
            elem: '#date'
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("是否确认修改!", {
                title: '最终的提交信息'
            }, function () {
                $.ajax({
                    type: "POST",
                    url: "/system/user/updatePass",
                    data: {
                        "oldPassword": data.field.oldPassword,
                        "newPassword": data.field.newPassword,
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code === 200) {
                            // 关闭弹出层
                            layer.alert(data.message, function () {
                                top.location = "/logout";
                            })
                            layer.close(index);
                        } else {
                            layer.alert(data.message)
                        }
                    }
                });
            });
            return false;
        });
    });
</script>
</body>
</html>